﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Security
{
    class ConfigHelper : Singleton<ConfigHelper>
    {
        private String processConfigFile = "cnf.json";
        private String appFilePath;
        public String AppFilePath
        {
            get
            {
                return appFilePath;
            }
            set
            {
                appFilePath = value;
            }
        }

        // 初始化
        public void Init()
        {
            // 获取程序运行位置
            appFilePath = System.AppDomain.CurrentDomain.BaseDirectory;
            LogHelper.Instance.WriteLog("appFilePath:" + appFilePath);
            LoadConfig();
        }

        // 加载配置信息
        public void LoadConfig()
        {
            String cnfFlie = appFilePath + processConfigFile;
            StreamReader jsonReader = File.OpenText(cnfFlie);
            String strjson = jsonReader.ReadToEnd();
            Check.Instance.SetCheckProcess(JsonConvert.DeserializeObject<IList<ProcessInfo>>(strjson));
        }
    }
}
